dojo.require("dojo.data.ItemFileWriteStore");
require(["dojo/json",
        "dojo/data/ObjectStore",
        "dojox/grid/enhanced/plugins/Pagination",
        "dojox/grid/enhanced/plugins/Filter",
        "dojox/grid/EnhancedGrid",
        "dojo/store/JsonRest",
        "dojox/grid/_CheckBoxSelector",
        "dojox/grid/cells",
        "dojo/domReady!"],
    function (JSON,
              ObjectStore,
              Pagination,
              Filter,
              EnhancedGrid,
              JsonRest,
              _CheckBoxSelector,
              cells) {

        var jsonRest = new JsonRest({target: "/data"});

        var dataStore = new ObjectStore({objectStore: jsonRest});

        var layout = [
            {type: "dojox.grid._CheckBoxSelector", width: '28px'},
            [[
                new cells.RowIndex({width: "45px", name: "序号"}),
                {'name': 'ID', 'field': 'id', 'width': '100px'},
                {'name': '用户名', 'field': 'username', 'width': '100px'},
                {'name': '密码', 'field': 'password', 'width': '200px'},
                {'name': '管理员', 'field': 'isadmin', 'width': '200px'},
                {'name': '性别', 'field': 'sex', 'width': '200px'},
                {'name': '创建时间', 'field': 'createTime', 'width': '200px'},
                {'name': '修改时间', 'field': 'updateTime', 'width': '200px'}
            ]]
        ];
        var grid = new EnhancedGrid({
                class: "grid",
                store: dataStore,
                structure: layout,
                columnReordering: true,
                clientSort: true,
                rowSelector: '0px',
                rowsPerPage: 10,
                autoHeight: false,
                style: {height: "99.8%"},
                noDataMessage: "当前无信息！",
                plugins: {
                    pagination: {
                        pageSizes: ["10", "25", "50", "100"],
                        description: true,
                        sizeSwitch: true,
                        pageStepper: true,
                        gotoButton: true,
                        maxPageStep: 10,
                        itemTitle: 'items',
                        position: "bottom"
                    },
                    filter: {
                        ruleCount: 5,
                        closeFilterbarButton: true,
                        itemsName: "items",
                        isServerSide: true,
                        setupFilterQuery: function (commands, request) {
                            if (commands.filter && commands.enable) {
                                request.query = {"filter": JSON.stringify(commands.filter)};
                            } else {

                            }
                        }
                    }
                }
            },
            "grid"
            )
            ;
        grid.startup();
        loading && loading.endLoading();
    });
